18. Converting Notebooks

Converting Notebooks

Notebooks are just big JSON files with the extension .ipynb.

Notebook file opened in a text editor shows JSON data

Notebook file opened in a text editor shows JSON data

Since notebooks are JSON, it is simple to convert them to other formats. Jupyter comes with a utility called nbconvert for converting to HTML, Markdown, slideshows, etc. The general syntax to convert a given mynotebook.ipynb file to another FORMAT is:

jupyter nbconvert --to FORMAT mynotebook.ipynb

The currently supported output FORMAT could be either of the following (ignore case):

  1. HTML,
  2. LaTeX,
  3. PDF,
  4. WebPDF,
  5. Reveal.js HTML slideshow,
  6. Markdown,
  7. Ascii,
  8. reStructuredText,
  9. executable script,
  10. notebook.

For example, to convert a notebook to an HTML file, in your terminal use

# Install the package below, if not already
pip install nbconvert
jupyter nbconvert --to html mynotebook.ipynb

Note - If you wish to install any package in conda that is not available in Anaconda distribution, such as the Airbase package, use pip install airbase, instead of conda install airbase.

Converting to HTML is useful for sharing your notebooks with others who aren't using notebooks. Markdown is great for including a notebook in blogs and other text editors that accept Markdown formatting.

As always, learn more about nbconvert from the documentation.

Notebook Supported File Formats

Which of the following is not a supported output file format to which you can convert a given Notebook file?

SOLUTION: .docx